﻿@inject IDataCacheService _dataCacheService


@if (Model.Count == 0)
{
    <NotFoundCard  Fill/>
}
else
{
    @foreach (var item in Model.Skip((CurrentPage - 1) * MaxCount).Take(MaxCount))
    {
        <MessageViewTip Model="item" />
    }

    @if (TotalPages > 1)
    {
        <CnGalWebSite.Components.Paginations.MasaPagination Value="@CurrentPage"  Length="@TotalPages" ValueChanged="OnPageClick"/>
    }
}

@code {
    [Parameter]
    public List<CnGalWebSite.DataModel.Model.Message> Model { get; set; }

    private int MaxCount { get; set; } = 10;

    private int TotalPages { get; set; }

    private int CurrentPage { get; set; } = 1;

    protected override void OnInitialized()
    {
        TotalPages = (Model.Count-1) / MaxCount + 1;
    }

    private void OnPageClick(int pageIndex)
    {
        CurrentPage = pageIndex;
        StateHasChanged();
        
    }
}
